package {
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import net.hires.debug.Stats;
	
	import org.wak.main.AdventureMaster;
	
	import puzzle.MyPuzzleController;
	
	[SWF(width=550,height=400, backgroundColor=0x555555, frameRate="60")]
	public class wakBase extends Sprite
	{
		
		//Need to retain a static reference to the initial stage size,
		//this is so the scrolling works as it should over multiple scenes.
		//the scrolling checks the background image size, which never changes.
		//scrolling compares the image size to the stage size, if that changes, the scrolling stops working.
		//If this could be automatic, even better! less code to edit. 
		public static const STAGE_WIDTH:Number = 550;
		public static const STAGE_HEIGHT:Number = 400;
		
		private var mAdvMaster:AdventureMaster ;

		public function wakBase()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			CreateMenu();
			//Initialize();
		}
		
		public function CreateMenu():void
		{
			graphics.beginFill(0x000000);
			graphics.drawRoundRect(stage.stageWidth/2 - 100, stage.stageHeight/2 - 100, 200,200, 10,10);
			graphics.endFill();
			
			var startGame:TextField = new TextField();
			startGame.text = "Start New Game";
			startGame.textColor = 0xffffff;
			startGame.x = stage.stageWidth/2 - startGame.width/2;
			startGame.y = stage.stageHeight/2 - 20;
			startGame.addEventListener(MouseEvent.CLICK, startNewGame);
			
			addChild(startGame);
			
			var loadGame:TextField = new TextField();
			loadGame.text = "Load Game";
			loadGame.textColor = 0xffffff;
			loadGame.x = stage.stageWidth/2 - loadGame.width/2;
			loadGame.y = stage.stageHeight/2;
			loadGame.addEventListener(MouseEvent.CLICK, loadGameMode);
			
			addChild(loadGame);
		}
		
		private function startNewGame(e:MouseEvent):void
		{
			Initialize(0);
		}
		
		private function loadGameMode(e:MouseEvent):void
		{
			Initialize(1);
		}
		
		public function Initialize(gameType:int):void
		{
			// Initialization of the adventure
			mAdvMaster = new AdventureMaster();
			mAdvMaster.SetMainClass(this);
			mAdvMaster.SetResMngr(Resources);
			mAdvMaster.Initialize() ;
			
			// Adding puzzle controllers
			mAdvMaster.AddPuzzleController( new MyPuzzleController() );
			
			//switching game start up modes.
			if(gameType == 0)
			{
				mAdvMaster.Start();
			}
			else
			{
				mAdvMaster.StartSavedGame();
			}
			
			addChild(new Stats());
		}
		
		
		
	}
}
